<!--
 * @author  guojiteng
 新建/编辑投票
-->
<template>
  <div class="vote-create">
    <div class="vote-create-title">新建/编辑投票</div>
    <section v-loading="loading" class="vote-create-main">
      <el-form ref="form" :model="form" :rules="rules" label-width="160px" class="form">
        <!-- <el-form-item label="创建方式" prop="createType">
          <el-radio-group v-model="form.createType">
            <el-radio v-for="(item, index) in dict.WJCJFS" :key="index" :label="item.dictValue" border @click.native="optionType(item.dictValue)">{{
              item.dictName
            }}</el-radio>
          </el-radio-group>
        </el-form-item> -->
        <!-- <el-form-item v-if="form.createType === 'WJX'" label="问卷星url" prop="urlCreate">
          <el-input v-model="form.urlCreate" placeholder="请输入问卷星url地址" />
        </el-form-item> -->
        <el-form-item label="活动类型" prop="classifyId">
          <el-radio-group v-model="form.classifyId">
            <el-radio v-for="(item, index) in dict.HDZXFXPC" :key="index" :label="item.dictValue">{{ item.dictName }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="投票名称" prop="votingName">
          <el-input v-model="form.votingName" placeholder="请输入投票名称" />
        </el-form-item>
        <!--        <el-form-item label="投票简介" prop="briefIntroduction">-->
        <!--          <el-input-->
        <!--            v-model="form.briefIntroduction"-->
        <!--            :autosize="{ minRows: 2, maxRows: 4 }"-->
        <!--            type="textarea"-->
        <!--            placeholder="请输入投票简介"-->
        <!--          />-->
        <!--        </el-form-item>-->

        <el-form-item label="引导图" prop="coverImgId" required>
          <image-upload
            :key="uploadFile.imagecropperKey"
            v-model="form.coverImgId"
            :preview-id="uploadFile.viewId"
            :forever="true"
            :width="750"
            :view="uploadFile.view"
            :height="330"
            :no-circle="true"
            :no-rotate="false"
            lang-type="zh"
          />
        </el-form-item>
        <el-form-item v-if="form.createType === 'LOAD'" label="活动简介">
          <tinymce v-if="showtinymce" v-model="form.votingRemark" :height="300" />
        </el-form-item>
        <el-form-item label="投票范围" prop="votingRange">
          <el-radio-group v-model="form.votingRange">
            <el-radio v-for="(item, index) in dict.TPKFFW" :key="index" :label="item.dictValue">{{ item.dictName }}</el-radio>
          </el-radio-group>
          <el-cascader
            v-if="form.votingRange == 'TPKFFW_BM'"
            ref="org"
            v-model="form.votingDeptIds"
            style="width: 100%"
            collapse-tags
            clearable
            :props="orgProps"
            :options="orgTreeData"
          />
        </el-form-item>
        <el-form-item label="展示范围" prop="openRange">
          <el-radio-group v-model="form.openRange">
            <el-radio v-for="(item, index) in dict.TPKFFW" :key="index" :label="item.dictValue">{{ item.dictName }}</el-radio>
          </el-radio-group>
          <el-cascader
            v-if="form.openRange == 'TPKFFW_BM'"
            ref="org"
            v-model="form.deptIds"
            style="width: 100%"
            collapse-tags
            clearable
            :props="orgProps"
            :options="orgTreeData"
          />
        </el-form-item>
        <el-form-item label="投票开始时间" prop="startTime">
          <el-date-picker
            v-model="form.startTime"
            style="width: 100%"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="选择日期时间"
          />
        </el-form-item>
        <el-form-item label="投票结束时间" prop="endTime">
          <el-date-picker
            v-model="form.endTime"
            style="width: 100%"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="选择日期时间"
            default-time="23:59:59"
          />
        </el-form-item>
        <el-form-item v-if="form.createType === 'LOAD'" label="每人每天投票次数">
          <el-input v-model.number="form.dailyLimit" oninput="value=value.replace(/[^0-9]/g,'')" :disabled="meiri" style="width: 90%" placeholder="请输入" />
          <el-checkbox v-model="meiri">无上限</el-checkbox>
        </el-form-item>
        <el-form-item v-if="form.createType === 'LOAD'" label="每人总共投票次数">
          <el-input v-model.number="form.everybodyLimit" oninput="value=value.replace(/[^0-9]/g,'')" :disabled="meiren" style="width: 90%" placeholder="请输入" />
          <el-checkbox v-model="meiren">无上限</el-checkbox>
        </el-form-item>
        <el-form-item label="职工端每页展示票数">
          <el-input
            v-model.number="form.showLimit"
            oninput="value=value.replace(/[^0-9]/g,'')"
            :disabled="showLimitCheck"
            style="width: 90%"
            placeholder="请输入"
          />
          <el-checkbox v-model="showLimitCheck">无上限</el-checkbox>
        </el-form-item>
        <el-form-item v-if="form.createType === 'LOAD'" label="是否展示已投票人数">
          <el-radio-group v-model="form.isShowNumber">
            <el-radio label="0">否</el-radio>
            <el-radio label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="form.createType === 'LOAD'" label="结束后是否允许查看">
          <el-radio-group v-model="form.isExpried">
            <el-radio label="0">否</el-radio>
            <el-radio label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="form.createType === 'LOAD'" label="最少可选项数">
          <el-input v-model.number="form.minQuantity" placeholder="请输入" />
        </el-form-item>
        <el-form-item v-if="form.createType === 'LOAD'" label="最多可选项数">
          <el-input v-model.number="form.maxQuantity" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="是否展示投票项数">
          <el-radio-group v-model="form.isShowOptions">
            <el-radio :label="0">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否展示投票累计数量">
          <el-radio-group v-model="form.isShowCount">
            <el-radio :label="0">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否展示访问量">
          <el-radio-group v-model="form.isShowVisitNum">
            <el-radio :label="0">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 加入抽奖相关 -->
        <el-form-item label="是否关联抽奖" prop="isDraw">
          <el-radio-group v-model="form.isDraw">
            <el-radio label="0">否</el-radio>
            <el-radio label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="职工端是否展示">
          <el-radio-group v-model="form.isAppVisit">
            <el-radio label="0">否</el-radio>
            <el-radio label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="form.isDraw === '1'" label="每日投票几次可获得抽奖" prop="everydayNeedNum">
          <el-input v-model.number="form.everydayNeedNum" placeholder="请输入" />
        </el-form-item>
        <el-form-item v-if="form.isDraw === '1'" label="可获得多少次抽奖机会" prop="drawChance">
          <el-input v-model.number="form.drawChance" placeholder="请输入" />
        </el-form-item>
        <el-form-item v-if="form.isDraw === '1'" label="一共可获得多少次抽奖机会" prop="allDrawTimes">
          <el-input v-model.number="form.allDrawTimes" placeholder="请输入" />
        </el-form-item>
        <el-form-item v-if="form.isDraw === '1'" label="抽奖配置" prop="bigturntableId">
          <div>
            <el-button class="button-new-tag" size="small" @click="showInputRwys">抽奖配置</el-button>
          </div>
          <div>
            <el-tag v-if="dialogMultipleSelections.bigturntableName !== undefined" closable @close="handleCloses(dialogMultipleSelections)">
              {{ dialogMultipleSelections.bigturntableName || bigturntableName }}
            </el-tag>
          </div>
        </el-form-item>
        <el-form-item v-if="form.isDraw === '1'" label="抽奖弹窗标题" prop="popTitle">
          <el-input v-model="form.popTitle" autosize placeholder="请输入" />
        </el-form-item>
        <el-form-item v-if="form.isDraw === '1'" label="抽奖弹窗引导按钮" prop="popButton">
          <el-input v-model="form.popButton" autosize placeholder="请输入" />
        </el-form-item>
        <el-form-item v-if="form.isDraw === '1'" label="抽奖弹窗样式选择" prop="popStyle">
          <el-select v-model="form.popStyle" autosize placeholder="请选择">
            <el-option v-for="item in popStyleList" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
          <el-image style="width: 375px;margin-top: 10px;" :src="popStyleList[form.popStyle].imagesOss" />
        </el-form-item>
        <el-form-item v-if="form.isDraw === '1'" label="抽奖活动说明" prop="drawExplain">
          <el-input v-model="form.drawExplain" autosize type="textarea" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input v-model.number="form.sort" placeholder="请输入排序号（值越大，越靠前）" />
        </el-form-item>
      </el-form>
    </section>
    <section class="vote-create-footer">
      <el-button
        style="padding: 10px 30px"
        @click="
          () => {
            $router.back()
          }
        "
      >取 消</el-button>
      <el-button type="primary" @click="onSubmint('form')">确 定</el-button>
    </section>
    <Upload
      v-if="uploadFile.showUpload"
      ref="upload"
      :accept="uploadFile.accept"
      :limit="1"
      :show-chunks="true"
      :multiple="false"
      :chunk-size="uploadFile.chunksize"
      @close="uploadFile.showUpload = false"
      @success="uploadSuccess"
    >
      <div slot="tip" class="upload-tip">
        <i class="el-icon-info" />
        :
        {{ uploadFile.fileType | filterTip }}
      </div>
    </Upload>
    <!-- 选择转盘 -->
    <el-dialog title="选择抽奖配置" :visible.sync="dialogFormVisibles" center fullscreen :close-on-click-modal="false">
      <choose-prize
        ref="resetAll"
        v-loading.fullscreen.lock="fullscreenLoadings"
        :before-list="beforeLists"
        :bigturntable-id="form.bigturntableId"
        @userData="userDatas"
      />
      <div slot="footer" class="dialog-footer">
        <el-button style="padding: 8px 30px" @click="dialogFormVisibles = false">取消</el-button>
        <el-button style="padding: 8px 30px" type="primary" @click="insertUsers()">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import ImageUpload from '@/components/ImageUpload'
import Upload from '@/components/upload'
import ChoosePrize from '@/views/activity/tphd/components/choosePrize'
import { mapGetters } from 'vuex'
import { getComAndOrgTree, getDictByCode, insert, update, get } from '../api/index'
import Tinymce from '@/components/Tinymce'
import elDragDialog from '@/directive/el-drag-dialog' // base on element-ui
export default {
  name: 'Votemanage',
  components: { ImageUpload, Upload, Tinymce, ChoosePrize },
  directives: { elDragDialog },
  filters: {
    filterTip(ft) {
      if (ft === 'image') {
        return '只能上传：图片文件'
      } else if (ft === 'video') {
        return '只能上传：视频文件'
      } else {
        return '请上传附件'
      }
    }
  },
  data() {
    return {
      popStyleList: [
        {
          id: 0,
          name: '样式一',
          imagesOss: 'https://bjttsx-yanshi.oss-cn-beijing.aliyuncs.com/1/22/12/02/221202cc96931db26743919206900e8a2f390d.png'
        },
        {
          id: 1,
          name: '样式二',
          imagesOss: 'https://bjttsx-yanshi.oss-cn-beijing.aliyuncs.com/1/22/12/02/22120231f566d987e046718fe2eeae498020b6.png'
        },
        {
          id: 2,
          name: '样式三',
          imagesOss: 'https://bjttsx-yanshi.oss-cn-beijing.aliyuncs.com/1/22/12/02/2212027a85a262f6da40b8ab08ff5f8788f276.png'
        },
        {
          id: 3,
          name: '样式四',
          imagesOss: 'https://bjttsx-yanshi.oss-cn-beijing.aliyuncs.com/1/22/12/02/221202d7f2d0d9c2cd40d1a474301bdae7e155.png'
        },
        {
          id: 4,
          name: '样式五',
          imagesOss: 'https://bjttsx-yanshi.oss-cn-beijing.aliyuncs.com/1/22/12/02/2212026bf78ddb405c4affa83fab281ba8cf02.png'
        },
        {
          id: 5,
          name: '样式六',
          imagesOss: 'https://bjttsx-yanshi.oss-cn-beijing.aliyuncs.com/1/22/12/02/221202827b3f4b16a54addb0ae0fdc1d0ac910.png'
        },
        {
          id: 6,
          name: '样式七',
          imagesOss: 'https://bjttsx-yanshi.oss-cn-beijing.aliyuncs.com/1/22/12/02/221202ff3f9084d3bb4f1abb6ca173f24a253b.png'
        },
        {
          id: 7,
          name: '样式八',
          imagesOss: 'https://bjttsx-yanshi.oss-cn-beijing.aliyuncs.com/1/22/12/02/2212022fc3e4e4f9484ceabea370fab0c5e407.png'
        }
      ],
      dialogMultipleSelections: {},
      beforeLists: [],
      fullscreenLoadings: false,
      dialogFormVisibles: false,
      orgProps: {
        label: 'name',
        value: 'id',
        children: 'list',
        multiple: true,
        emitPath: false,
        checkStrictly: true
      },
      orgTreeData: [],
      loading: false,
      showtinymce: false,
      meiri: true,
      meiren: true,
      form: {
        popTitle: '',
        popButton: '',
        popStyle: 0,
        bigturntableId: '',
        everydayNeedNum: 0,
        drawChance: 0,
        allDrawTimes: 0,
        drawExplain: '',
        isDraw: '0',
        id: '',
        createType: 'LOAD',
        urlCreate: '',
        classifyId: '', // type
        votingName: '',
        coverImgId: '',
        votingRemark: '',
        briefIntroduction: '',
        openRange: '',
        deptIds: [],
        startTime: '',
        endTime: '',
        dailyLimit: '',
        everybodyLimit: '',
        isShowNumber: '1',
        isExpried: '0', // 0 否 1是
        minQuantity: '',
        maxQuantity: '',
        sort: '',
        votingRange: '', // 展示范围
        votingDeptIds: [], // 展示范围的部门id
        isShowVisitNum: 1,
        isShowOptions: 1,
        isShowCount: 1,
        showLimit: '',
        isAppVisit: '1'
      },
      showLimitCheck: true,
      rules: {
        /* classifyId: [
          { required: true, message: '请选择投票类型 ', trigger: 'change' }
        ],*/
        // createType: [{ required: true, message: '请选择投票创建的方式', trigger: 'blur' }],
        // urlCreate: [
        //   {
        //     required: true,
        //     message: '请输入问卷星投票url地址',
        //     trigger: 'blur'
        //   }
        // ],
        votingName: [
          { required: true, message: '请输入投票名称', trigger: 'blur' },
          {
            min: 1,
            max: 200,
            message: '长度在 1 到 200 个字符',
            trigger: 'blur'
          }
        ],
        bigturntableId: [
          {
            required: true,
            message: '请关联抽奖配置',
            trigger: 'blur'
          }
        ],
        startTime: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
        endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }],
        isDraw: [{ required: true, message: '请选择是否关联抽奖', trigger: 'change' }],
        everydayNeedNum: [{ required: true, message: '请输入投票几次可获得抽奖', trigger: 'change' }],
        drawChance: [{ required: true, message: '请输入可获得多少次抽奖机会', trigger: 'change' }],
        allDrawTimes: [{ required: true, message: '请输入一共可获得多少次抽奖机会', trigger: 'change' }],
        drawExplain: [{ required: true, message: '请输入抽奖活动说明', trigger: 'change' }],
        coverImgId: [{ required: true, message: '请上传引导图', trigger: 'change' }],
        votingRange: [{ required: true, message: '请选择投票范围', trigger: 'change' }],
        openRange: [{ required: true, message: '请选择展示范围', trigger: 'change' }]
      },
      imagesList: [],
      videosList: [],
      filesList: [],
      imageaddState: false,
      imageadd: {
        attachmentId: '',
        explain: '',
        attachmentName: ''
      },
      state: 'create',
      classifyOptions: [],
      uploadFile: {
        viewId: '',
        view: '/API-DOCUMENT/document/file/download?id=',
        imagecropperKey: 0,
        showUpload: false,
        accept: '',
        fileType: '',
        fileIndex: 0
      },
      dict: {
        TPKFFW: [], // 审核状态
        WJCJFS: [],
        HDZXFXPC: []
      }
    }
  },
  watch: {
    meiri(val) {
      if (val) {
        this.form.dailyLimit = ''
      }
    },
    meiren(val) {
      if (val) {
        this.form.everybodyLimit = ''
      }
    },
    'form.bigturntableId'(newVal) {
      if (newVal) {
        this.$refs['form'].clearValidate(['bigturntableId'])
      }
    }
  },
  computed: {
    ...mapGetters(['user'])
  },
  created() {
    for (const key in this.dict) {
      this.getDict(key)
    }
    this.state = this.$route.query.type === 'u' ? 'update' : 'create'
    this.getOrgTree()
    if (this.$route.query.type === 'u') {
      if (!this.$route.query.i) {
        this.$message({
          showClose: true,
          message: '参数异常！',
          type: 'warning',
          onClose: () => {
            this.$router.back()
          }
        })
        return
      }
      this.getData(this.$route.query.i)
    } else {
      this.showtinymce = true
    }
  },
  methods: {
    handleCloses(dialogMultipleSelections) {
      this.dialogMultipleSelections = {}
      this.form.bigturntableId = ''
    },
    // 确定选择抽奖配置
    insertUsers() {
      console.log('111111', this.dialogMultipleSelections)
      if (JSON.stringify(this.dialogMultipleSelections) === '{}') {
        this.$message({
          message: '请选择抽奖配置',
          type: 'warning'
        })
      } else {
        this.$set(this.form, 'bigturntableId', this.dialogMultipleSelections.id)
        this.dialogListLoadings = true
        this.dialogFormVisibles = false
      }
    },
    // 选择人物元素
    userDatas(val) {
      console.log('11111', val)
      this.dialogMultipleSelections = val
    },
    // 选择转盘
    showInputRwys() {
      this.dialogFormVisibles = true
    },
    // optionType(dictValue){
    //   if(dictValue === 'WJX'){
    //     var url = "https://www.wjx.cn/newwjx/mysojump/createblankNew.aspx";
    //     window.open(url, "_blank");
    //   }
    // },
    getOrgTree() {
      return new Promise((resolve, reject) => {
        getComAndOrgTree({ parentId: -1, orgId: this.user.orgId })
          .then((res) => {
            this.orgTreeData = res.data.data
          })
          .catch(() => {
            resolve([])
          })
      })
    },
    getDict(code) {
      return new Promise((resolve, reject) => {
        getDictByCode(code)
          .then((res) => {
            this.dict[code] = res.data.data && res.data.data.length > 0 ? res.data.data[0].list : []
          })
          .catch((error) => {
            reject(error)
          })
      })
    },
    CleanPastedHTML(input) {
      if (!input) {
        return ''
      }
      input = input.replace(/<\/?[^>]*>/g, '') // 去除HTML tag
      input = input.replace(/(\r)/gi, '')
      input = input.replace(/(\n)/gi, '')
      input = input.replace(/(\t)/gi, '')
      input = input.replace(/ /gi, '') // 去掉
      return input.replace(/&(.*?);/gi, '')
    },

    isEmpty(e) {
      if (e.target.value === '') {
        this.$message({
          message: '附件名称不能为空！',
          type: 'warning'
        })
      }
    },
    handleFileUpload(fileType, i) {
      this.uploadFile.fileType = fileType
      this.uploadFile.fileIndex = i
      if (fileType === 'video') {
        this.uploadFile.accept = 'video/mp4'
      } else if (fileType === 'image') {
        this.uploadFile.accept = 'image/*'
      } else {
        this.uploadFile.accept = ''
      }
      this.uploadFile.showUpload = true
    },
    /**
     * 新闻图片-继续添加
     */
    imagesAdd() {
      for (const i in this.imageadd) {
        this.imageadd[i] = ''
      }
      this.imageaddState = true
    },
    submitUploadImage() {
      const obj = Object.assign({}, this.imageadd)
      this.imagesList.push(obj)
      this.imageaddState = false
    },
    /**
     * 新闻视频-继续添加
     */
    videosAdd() {
      if (this.videosList.length === 0 || this.videosList[this.videosList.length - 1].attachmentId !== '') {
        const temp = {
          attachmentId: '',
          explain: '',
          attachmentName: ''
        }
        this.videosList.push(temp)
      }
      this.handleFileUpload('video', this.videosList.length - 1)
    },
    /**
     * 新闻附件-继续添加
     */
    filesAdd() {
      const temp = {
        attachmentId: '',
        explain: '',
        attachmentName: '',
        attachmentNameOld: ''
      }
      this.filesList.push(temp)
      this.handleFileUpload('file', this.filesList.length - 1)
    },
    /**
     * 新闻图片-删除
     */
    imagesDel(item, index) {
      this.$confirm('确定删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.imagesList.splice(index, 1)
        })
        .catch()
    },
    /**
     * 新闻视频-删除
     */
    videosDel(item, index) {
      this.$confirm('确定删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.videosList.splice(index, 1)
        })
        .catch()
    },
    /**
     * 新闻附件-删除
     */
    filesDel(item, index) {
      this.$confirm('确定删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.filesList.splice(index, 1)
        })
        .catch()
    },
    uploadSuccess(id, files) {
      if (id) {
        const fileType = this.uploadFile.fileType
        const fileIndex = this.uploadFile.fileIndex
        if (fileType === 'image') {
          this.imageadd.attachmentId = id
          this.imageadd.attachmentName = files[0].name
        } else if (fileType === 'video') {
          this.videosList[fileIndex].attachmentId = id
          this.videosList[fileIndex].attachmentName = files[0].name
        } else {
          this.filesList[fileIndex].attachmentId = id
          this.filesList[fileIndex].attachmentName = files[0].name
          this.filesList[fileIndex].attachmentNameOld = files[0].name
        }
      }
      this.uploadFile.showUpload = false
    },

    onSubmint() {
      console.log(this.form)
      if (
        this.filesList
          .filter((item) => {
            return item.attachmentId
          })
          .filter((ite) => {
            return ite.attachmentName === ''
          }).length > 0
      ) {
        this.$message({
          message: '请填写附件名称！',
          type: 'warning'
        })
        return
      }
      if (this.state === 'create') {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            const params = Object.assign({}, this.form)
            // 展示范围
            if (params.openRange === 'TPKFFW_BM') {
              if (params.deptIds.length === 0 || params.deptIds[0] === '') {
                this.$message.error('请选择展示范围的部门')
                return
              }
              params.deptIds = params.deptIds.join(',')
            } else {
              params.deptIds = ''
            }
            // 投票范围
            if (params.votingRange === 'TPKFFW_BM') {
              if (params.votingDeptIds.length === 0 || params.votingDeptIds[0] === '') {
                this.$message.error('请选择投票范围的部门')
                return
              }
              params.votingDeptIds = params.votingDeptIds.join(',')
            } else {
              params.votingDeptIds = ''
            }
            delete params.id
            if (this.meiri === true) {
              params.dailyLimit = -1
            }
            if (this.meiren === true) {
              params.everybodyLimit = -1
            }
            if (this.showLimitCheck === true) {
              params.showLimit = -1
            }
            const loading = this.$loading({
              lock: true,
              text: '请稍后',
              spinner: 'el-icon-loading',
              background: 'rgba(0, 0, 0, 0.3)'
            })
            return new Promise((resolve, reject) => {
              insert(params)
                .then(() => {
                  this.dialogVisible = false
                  loading.close()
                  this.$message({
                    title: '成功',
                    message: '创建成功',
                    type: 'success',
                    duration: 2000
                  })
                  this.$router.back()
                })
                .catch((error) => {
                  reject(error)
                  loading.close()
                })
            })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      } else {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            const params = Object.assign({}, this.form)
            if (params.openRange === 'TPKFFW_BM') {
              if (params.deptIds.length === 0 || params.deptIds[0] === '') {
                this.$message.error('请选择展示范围的部门')
                return
              }
              params.deptIds = params.deptIds.join(',')
            } else {
              params.deptIds = ''
            }
            // 投票范围
            if (params.votingRange === 'TPKFFW_BM') {
              if (params.votingDeptIds.length === 0 || params.votingDeptIds[0] === '') {
                this.$message.error('请选择投票范围的部门')
                return
              }
              params.votingDeptIds = params.votingDeptIds.join(',')
            } else {
              params.votingDeptIds = ''
            }
            const loading = this.$loading({
              lock: true,
              text: '请稍后',
              spinner: 'el-icon-loading',
              background: 'rgba(0, 0, 0, 0.3)'
            })
            if (this.meiri === true) {
              params.dailyLimit = -1
            }
            if (this.meiren === true) {
              params.everybodyLimit = -1
            }
            if (this.showLimitCheck === true) {
              params.showLimit = -1
            }
            return new Promise((resolve, reject) => {
              update(params)
                .then(() => {
                  this.dialogVisible = false
                  loading.close()
                  this.$message({
                    title: '成功',
                    message: '修改成功',
                    type: 'success',
                    duration: 2000
                  })
                  this.$router.back()
                })
                .catch((error) => {
                  reject(error)
                  loading.close()
                })
            })
          } else {
            return false
          }
        })
      }
    },
    /**
     * 根编辑回显
     */
    getData(id) {
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      return new Promise((resolve, reject) => {
        get({ id: id })
          .then((res) => {
            loading.close()
            const data = res.data.data
            for (const key in this.form) {
              if (key === 'dailyLimit') {
                this.meiri = +data[key] === -1
                this.form[key] = +data[key] === -1 ? '' : data[key]
              } else if (key === 'everybodyLimit') {
                this.meiren = +data[key] === -1
                this.form[key] = +data[key] === -1 ? '' : data[key]
              } else if (key === 'deptIds' && data.deptIds) {
                this.form[key] = data.deptIds.split(',').filter((item) => {
                  return item
                })
              } else if (key === 'votingDeptIds' && data.votingDeptIds) {
                this.form[key] = data.votingDeptIds.split(',').filter((item) => {
                  return item
                })
              } else if (key === 'showLimit') {
                this.showLimitCheck = data.showLimit === -1
                this.form[key] = data[key] === -1 ? '' : data[key]
              } else if (key === 'createType') {
                this.form[key] = data[key] ? data[key] : 'LOAD'
              } else {
                this.form[key] = data[key]
              }
            }
            console.log(' this.form', this.form)
            this.$set(this.form, 'popStyle', this.form.popStyle ? this.form.popStyle : 0)
            this.$set(this, 'dialogMultipleSelections', {
              bigturntableName: res.data.data.bigturntableName,
              id: res.data.data.bigturntableId
            })
            this.uploadFile.viewId = data.coverImgId
            this.$nextTick(() => {
              this.showtinymce = true
            })
          })
          .catch((error) => {
            loading.close()
            reject(error)
          })
      })
    },
    dateFormat(fmt, date) {
      let ret
      const opt = {
        'y+': date.getFullYear().toString(), // 年
        'M+': (date.getMonth() + 1).toString(), // 月
        'd+': date.getDate().toString(), // 日
        'H+': date.getHours().toString(), // 时
        'm+': date.getMinutes().toString(), // 分
        's+': date.getSeconds().toString() // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
      }
      for (const k in opt) {
        ret = new RegExp('(' + k + ')').exec(fmt)
        if (ret) {
          fmt = fmt.replace(ret[1], ret[1].length === 1 ? opt[k] : opt[k].padStart(ret[1].length, '0'))
        }
      }
      return fmt
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
.vote-create {
  background-color: #fff;
  min-height: calc(100vh - 60px);
  max-height: calc(100vh - 60px);
  overflow: hidden;
  .vote-create-title {
    position: relative;
    height: 40px;
    line-height: 40px;
    padding: 0 20px;
    background-color: #ffffff;
    border-bottom: 1px solid #e5e5e5;
    font-family: PingFangSC-Medium;
    font-weight: bold;
    color: rgba(51, 51, 51, 1);
    font-size: 14px;
    &:before {
      content: '';
      position: absolute;
      width: 2px;
      @include bg-color($mainColor);
      top: 13px;
      bottom: 13px;
      left: 15px;
    }
  }

  .vote-create-main {
    position: absolute;
    top: 50px;
    left: 0;
    right: 0;
    bottom: 52px;
    box-sizing: border-box;
    padding: 0 10px;
    overflow: hidden;
    &::-webkit-scrollbar {
      width: 8px; /*对垂直流动条有效*/
      height: 1px; /*对水平流动条有效*/
    }
    /** 滚动条轨道*/
    &::-webkit-scrollbar-track {
      box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.1);
      background-color: white;
      border-radius: 3px;
    }
    /** 滚动条里面小方块*/
    &::-webkit-scrollbar-thumb {
      height: 32px;
      border-radius: 5px;
      box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.1);
      background-color: #eaeaea;
    }
    &:hover {
      overflow: auto;
    }
    .form {
      width: 1000px !important;
      margin: 0 auto;
      .el-select {
        width: 100%;
      }

      .line {
        text-align: center;
      }
      .el-form-item__error{
        margin-top: 4px;
      }
    }
    .select-data {
      display: inline-block;
      background: rgba(246, 246, 246, 1);
      border-radius: 4px;
      font-size: 14px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      color: rgba(51, 51, 51, 1);
      padding: 0 10px;
      margin-right: 5px;
      margin-bottom: 8px;
      i {
        cursor: pointer;
        padding-left: 5px;
      }
    }
    .selectbtn {
      display: inline-block;
      width: 120px;
      background: rgba(255, 255, 255, 1);
      @include border-color(1px, dotted, $mainColor);
      border-radius: 4px;
      font-size: 14px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      @include font-color($mainColor);
      text-align: center;
      cursor: pointer;
      margin-bottom: 10px;
    }
    .vote-image {
      .el-card__header {
        padding-top: 8px;
        padding-bottom: 8px;
      }
    }
    .images-item {
      position: relative;
      margin-bottom: 10px;
      .upload-img {
        width: 100%;
        height: 160px;
        display: block;
      }
      .el-input {
        display: block;
      }
      .custom-uploader {
        width: 100%;
        display: block;
        .icon-wrap {
          width: 100%;
          height: 160px;
        }
      }
      .el-button {
        position: absolute;
        right: 10px;
        top: 0;
        color: #fff;
        i {
          background: rgba(0, 0, 0, 0.4);
          border-radius: 50%;
          padding: 2px;
        }
        &.image-index-move {
          right: 40px;
        }
      }
    }
    .images-add {
      color: $mainColor;
      font-size: 14px;
      padding-left: 80px;
      cursor: pointer;
      margin-bottom: 20px;
    }
    .upload-img {
      width: 100%;
      height: 160px;
    }
    .attachment-item {
      margin-bottom: 10px;
      .item-btn {
        font-size: 20px;
        cursor: pointer;
      }
      .video-item {
        position: relative;
        cursor: pointer;
        .el-button {
          position: absolute;
          right: 10px;
          top: 0;
          color: #fff;
          i {
            background: rgba(0, 0, 0, 0.4);
            border-radius: 50%;
            padding: 2px;
          }
          &.video-index-move {
            right: 40px;
          }
        }
      }
    }
  }

  .vote-create-footer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    text-align: center;
    padding: 10px 0;
    background-color: white;
    box-shadow: 0 -3px 6px #f5f5f5;
  }
  .image-upload-dialog {
    .icon-wrap {
      width: 300px;
      height: 160px;
      margin: 0 auto;
      display: flex;
      align-items: center;
      justify-content: center;
      background: rgba(247, 247, 248, 1);
      border: 1px solid rgba(226, 227, 232, 1);
      border-radius: 4px;
      .avatar-uploader-icon {
        font-size: 48px;
        color: #dadada;
        width: 300px;
        text-align: center;
      }
    }
   /* .upload-img {
      display: block;
      width: 300px;
      height: 160px;
      border-radius: 4px;
    }*/
  }
}
</style>
<style lang="scss">
.vote-create {
  .classify-tree-con {
    position: relative;
    height: 400px;
    overflow: hidden;
    .classify-tree-con-scrollbar {
      overflow: hidden;
      .el-scrollbar__wrap {
        max-height: 381px;
      }
    }
    .custom-tree-node {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14px;
      width: 100%;
      .tree-node-txt {
        flex: 1;
      }
    }
  }
  .el-tag--medium {
    line-height: 32px;
    height: 32px;
    & + .el-tag--medium {
      margin-left: 10px;
    }
  }
}
</style>
